import React from 'react'
import { connect } from "react-redux"
import store from './redux/store'
function App (props) {
  return (
    <div>
      <div>App</div>
      <button onClick={() => {
        if (props.list1.length === 0) {
          props.getList1()
          console.log(props.list1)
        } else {
          console.log("缓存", props.list1)
        }
      }}>click-ajax</button>
      <button onClick={() => {
        if (props.list2.length === 0) {
          props.getList2()
          console.log(props.list2)
        } else {
          console.log("缓存", props.list2)
        }
      }}>click-ajax</button>
    </div>
  )
}

const mapDispatchToProps = {
  getList1: () => {
    return {
      type: "get-list1"
    }
  },
  getList2: () => {
    return {
      type: "get-list2"
    }
  }
}
export default connect((state) => {
  return {
    list1: state.list1,
    list2: state.list2
  }
}, mapDispatchToProps)(App)